<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_POST['post'])) {
		$id = intval($_POST['id']);
		$nama = amankan($_POST['nama']);
		$harga = intval($_POST['harga']);
		$deskripsi = amankan($_POST['deskripsi']);
		$kategori = amankan($_POST['kategori']);
		if ($_FILES['image']['error'] == 0 || $_FILES['image']['error'] == 4) {
			$slug = slugging($_POST['nama'],"produk",$id);
			$kategori = kategoring($kategori);
			db_query("UPDATE produk SET nama = '$nama', slug = '$slug', harga = $harga, deskripsi = '$deskripsi', kategori = '$kategori' WHERE id = $id");
			rapikan_kategori();
			if ($_FILES['image']['error'] != 4) {
				move_uploaded_file($_FILES['image']['tmp_name'],asset_path()."/images/produk/".$id.".jpg");
			}
			$_SESSION['status-produk'] = "Produk sudah diedit";
			header("Location: ".site()."/".$param[0]."/produk");
		} else {
			$_SESSION['status-produk-edit'] = "Upload gagal. Error Code : ".$_FILES['image']['error'];
			header("Location: ".site()."/".$param[0]."/produk-edit/".$param[2]);
		}
	}
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>